package com.qf.advice;

import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.*;
import org.springframework.stereotype.Component;

@Component
@Aspect
public class MyAnnoAdvice {

    @Pointcut("execution(* com.qf.service.impl.GradeServiceImpl.*(..))")
    public void pc(){}

    @Before("pc()")
    public void before(){
        System.out.println("注解前置增强");
    }
    @AfterReturning(value = "pc()",returning = "result")
    public void afterReturning(Object result){
        System.out.println("注解后置增强");
        System.out.println("返回结果为："+result);
    }

    @Around("pc()")
    public void around(ProceedingJoinPoint proceedingJoinPoint)throws Throwable{
        System.out.println("注解环绕前置");
        Object proceed = proceedingJoinPoint.proceed();
        System.out.println("注解环绕后置，拿到了结果："+proceed);
    }
    @AfterThrowing(value = "pc()",throwing = "e")
    public void afterThrowing(Exception e){
        System.out.println("异常增强"+e.getMessage());
    }
    @After("pc()")
    public void after(){
        System.out.println("注解最终增强");
    }
}
